package com.glaciervirtualdevice.Generator;

import static com.glaciervirtualdevice.constant.DataConstant.*;

import java.util.Random;

public class HumidityGenerator {
    private static final Random random = new Random();
    private static int minHumidity;
    private static int maxHumidity;
    private static int stableHumidity;

    // 生成湿度数据
    private static void generateAllHumidity() {
        // 生成 13 到 -10 之间的最小湿度
        minHumidity = random.nextInt(LEFT_HUMI_MIN_RANDOM_LINE) - RIGHT_HUMI_MIN_RANDOM_LINE;
        // 生成 30 到 50 之间的最大湿度
        maxHumidity = random.nextInt(LEFT_HUMI_MAX_RANDOM_LINE) + RIGHT_HUMI_MAX_RANDOM_LINE;

        // 计算稳定湿度的范围
        int minStable = minHumidity + DIFFERENCE_VALUE;
        int maxStable = maxHumidity - DIFFERENCE_VALUE;

        // 确保范围有效
        if (minStable > maxStable) {
            int temp = minStable;
            minStable = maxStable;
            maxStable = temp;
        }

        // 生成稳定湿度
        stableHumidity = random.nextInt(maxStable - minStable + 1) + minStable;
    }

    // 获取最小湿度
    public static int getMinHumidity() {
        generateAllHumidity();
        return minHumidity;
    }

    // 获取最大湿度
    public static int getMaxHumidity() {
        generateAllHumidity();
        return maxHumidity;
    }

    // 获取稳定湿度
    public static int getStableHumidity() {
        generateAllHumidity();
        return stableHumidity;
    }
}    